import { defineStore } from "pinia";
import { setCookie, getCookie } from "@/utils/cookie";
const useUserStore = defineStore("user", {
    state: () => {
        return {
            //用户名
            userName: '',
            //账号昵称
            loginName: '',
            //用户id
            userId: ''
        }
    },
    actions: {
        //储存用户信息
        saveUserInfo(userInfo: any) {
            const expires = 60*60*24*3;
            this.userName = userInfo.user_name;
            this.userId = userInfo.user_id;
            this.loginName = userInfo.login_name;
            setCookie('userName',userInfo.user_name,expires);
            setCookie('userId',userInfo.user_id,expires);
            setCookie('loginName',userInfo.login_name,expires);
        },
        //重新设置用户信息
        setUserName() {
            this.userName = getCookie('userName') || '';
            this.userId = getCookie('userId') || '';
            this.loginName = getCookie('loginName') || '';
        }
    }
});

export default useUserStore;